using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_Client_RemindManage : Admin, IRequiresSessionState
{
	private string linkHead = "";
	private string beforeUrl = "Admin_Client_RemindManage.aspx?MenuID=2&MenuName=客户管理&FileName=预约提醒管理";
	private string actionTab = "";
	private int remindId = 0;
	protected ScriptManager ScriptManager1;
	protected Literal ltrTitle;
	protected HtmlTable table_item;
	protected TextBox txtBeginTime;
	protected TextBox txtEndTime;
	protected DropDownList ddlStatus;
	protected TextBox txtSearchClientName;
	protected DropDownList ddlDate;
	protected Button SeachBut;
	protected GridView gvManage;
	protected UpdatePanel UpdatePanel1;
	protected Literal ltrPagePanel;
	protected Panel pnlManage;
	protected Label lblClientName;
	protected Label lblRelationType;
	protected Label lblCorrelativeContacter;
	protected Label lblRemindFashion;
	protected Label lblRemindContent;
	protected Label lblCreateTime;
	protected Label lblRemindTime;
	protected Label lblCreater;
	protected Label lblResult;
	protected Panel pnlCheckInfo;
	public string ActionTab
	{
		get
		{
			if (base.Request.QueryString["action"] != null)
			{
				this.actionTab = base.Request.QueryString["action"].Trim();
			}
			else
			{
				this.actionTab = "";
			}
			return this.actionTab;
		}
		set
		{
			this.actionTab = value;
		}
	}
	public int RemindId
	{
		get
		{
			if (base.Request.QueryString["RemindId"] != null)
			{
				this.remindId = Convert.ToInt32(base.Request.QueryString["RemindId"].Trim());
			}
			return this.remindId;
		}
		set
		{
			this.remindId = value;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(44))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Admin_Client_RemindManage");
				base.WriteRightErrMsg();
			}
			this.ShowPanelDisplay(this.ActionTab);
		}
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		if (DisplayName != null)
		{
			if (DisplayName == "checkinfo")
			{
				this.pnlManage.Visible = false;
				this.pnlCheckInfo.Visible = true;
				if (this.RemindId > 0)
				{
					this.InitPage();
				}
				return;
			}
		}
		this.pnlManage.Visible = true;
		this.pnlCheckInfo.Visible = false;
		this.BindClientItem();
	}
	protected void InitPage()
	{
		HoWave.Data.Model.ClientRemindItem model = BLLInstance.BllClientRemindItem.GetModel(this.RemindId);
		if (model != null)
		{
			int clientID = Convert.ToInt32(model.CorrelativeClient);
			HoWave.Data.Model.Client model2 = HoWave.Data.Bll.Client.instance.GetModel(clientID);
			if (model2 != null)
			{
				string clientName = model2.ClientName;
				this.lblClientName.Text = clientName;
			}
			HoWave.Data.Model.ClientContacter contacterByTrueName = HoWave.Data.Bll.ClientContacter.instance.GetContacterByTrueName(model.CorrelativeContacter);
			if (contacterByTrueName != null)
			{
				this.lblCorrelativeContacter.Text = model.CorrelativeContacter;
			}
			this.lblRelationType.Text = this.GetDictionaryTitle(model.RelationType);
			this.lblRemindContent.Text = model.RemindContent;
			this.lblCreateTime.Text = model.CreateTime.ToString();
			this.lblRemindTime.Text = model.RemindTime.ToString();
			this.lblCreater.Text = model.Creater;
			this.lblResult.Text = this.GetResult(model.Status.ToString());
			if (model.RemindByEmail)
			{
				this.lblRemindFashion.Text = "邮件提醒&nbsp;";
			}
			else
			{
				if (model.RemindBySms)
				{
					Label expr_16E = this.lblRemindFashion;
					expr_16E.Text += "手机短信提醒&nbsp;";
				}
				else
				{
					if (model.RemindByTips)
					{
						Label expr_1A1 = this.lblRemindFashion;
						expr_1A1.Text += "冒泡提示提醒";
					}
				}
			}
		}
	}
	protected string GetDictionaryTitle(string fieldValue)
	{
		string result = "";
		HoWave.Data.Model.Dictionary dictionary = HoWave.Data.Bll.Dictionary.instance.GetDictionary(fieldValue);
		if (dictionary != null)
		{
			result = dictionary.FieldText;
		}
		return result;
	}
	protected void BindClientItem()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HL_Client as c,HL_ClientRemindItem as cri where cri.CorrelativeClient=c.ClientID ";
		int pageSize = this.gvManage.PageSize;
		ClientByPage clientByPage = new ClientByPage();
		int listCount = clientByPage.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = "ROW_NUMBER() OVER (" + queryByOrder + ") as row,c.ClientName,cri.* ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = clientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvManage.DataSource = listPage;
		this.gvManage.DataBind();
		CurrPageLinks currPageLinks = new CurrPageLinks();
		string url = this.beforeUrl + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = currPageLinks.CurrPageLink(num, pageSize, listCount, "条记录&nbsp;&nbsp;每页&nbsp;" + pageSize + "&nbsp;条记录", url);
		for (int i = 0; i < this.gvManage.Rows.Count; i++)
		{
			HiddenField hiddenField = (HiddenField)this.gvManage.Rows[i].FindControl("hfEmail");
			HiddenField hiddenField2 = (HiddenField)this.gvManage.Rows[i].FindControl("hfMobile");
			Image image = (Image)this.gvManage.Rows[i].FindControl("imgEmail");
			Image image2 = (Image)this.gvManage.Rows[i].FindControl("imgMobile");
			if (hiddenField != null)
			{
				if (hiddenField.Value.ToLower() == "true")
				{
					image.ImageUrl = "~/Images/Client/mail.gif";
				}
				if (hiddenField2.Value.ToLower() == "true")
				{
					image2.ImageUrl = "~/Images/Client/phone.gif";
				}
			}
		}
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("RemindTime");
		if (!string.IsNullOrEmpty(text2))
		{
			for (int i = 0; i < this.ddlDate.Items.Count; i++)
			{
				if (this.ddlDate.Items[i].Value == text2)
				{
					this.ddlDate.Items[i].Selected = true;
					break;
				}
			}
		}
		else
		{
			text2 = this.ddlDate.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2))
		{
			string text3 = text2;
			if (text3 != null)
			{
				if (!(text3 == "10"))
				{
					if (text3 == "30")
					{
						text += " and (RemindTime>=DATEADD(MM,-1,GETDATE()) and RemindTime<=DATEADD(MM,1,getdate()))";
					}
				}
				else
				{
					text += " and (DATEDIFF(DD,RemindTime,GETDATE())>=0 and DATEDIFF(DD,RemindTime,GETDATE())<=10)";
				}
			}
			this.linkHead = this.linkHead + "&RemindTime=" + text2;
		}
		string text4 = Fetch.Get("Status");
		if (!string.IsNullOrEmpty(text4))
		{
			for (int i = 0; i < this.ddlStatus.Items.Count; i++)
			{
				if (this.ddlStatus.Items[i].Value == text4)
				{
					this.ddlStatus.Items[i].Selected = true;
					break;
				}
			}
		}
		else
		{
			text4 = this.ddlStatus.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and Status=" + text4;
			this.linkHead = this.linkHead + "&Status=" + text4;
		}
		string text5 = Fetch.Get("BeginTime");
		if (!string.IsNullOrEmpty(text5))
		{
			this.txtBeginTime.Text = text5;
		}
		else
		{
			text5 = this.txtBeginTime.Text;
		}
		if (!string.IsNullOrEmpty(text5))
		{
			text = text + " and DATEDIFF(DD, RemindTime,'" + text5 + "')<=0";
			this.linkHead = this.linkHead + "&BeginTime=" + text5;
		}
		string text6 = Fetch.Get("EndTime");
		if (!string.IsNullOrEmpty(text6))
		{
			this.txtEndTime.Text = text6;
		}
		else
		{
			text6 = this.txtEndTime.Text;
		}
		if (!string.IsNullOrEmpty(text6))
		{
			if (!string.IsNullOrEmpty(text5))
			{
				if (Convert.ToDateTime(text5) > Convert.ToDateTime(text6))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			text = text + "and DATEDIFF(DD, RemindTime,'" + text6 + "')>=0";
			this.linkHead = this.linkHead + "&EndTime=" + text6;
		}
		string text7 = Fetch.Get("KeHuName");
		if (!string.IsNullOrEmpty(text7))
		{
			this.txtSearchClientName.Text = text7;
		}
		else
		{
			text7 = this.txtSearchClientName.Text;
		}
		if (!string.IsNullOrEmpty(text7))
		{
			text = text + " and c.ClientName like '%" + text7 + "%'";
			this.linkHead = this.linkHead + "&KeHuName=" + text7;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		string result = "order by cri.RemindId desc";
		string value = this.ddlDate.SelectedValue.Trim();
		if (!string.IsNullOrEmpty(value))
		{
			result = "order by cri.RemindTime desc";
		}
		string value2 = this.txtBeginTime.Text.Trim();
		string value3 = this.txtEndTime.Text.Trim();
		if (!string.IsNullOrEmpty(value2) || !string.IsNullOrEmpty(value3))
		{
			result = "order by cri.RemindTime desc";
		}
		return result;
	}
	protected void gvManage_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvManage_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindClientItem();
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.BindClientItem();
	}
	protected string GetResult(string value)
	{
		string result = value;
		if (value.ToString().ToLower() == "false")
		{
			result = "未处理";
		}
		else
		{
			if (value.ToString().ToLower() == "true")
			{
				result = "已处理";
			}
		}
		return result;
	}
}
